<!DOCTYPE html>
<html lang="en" xmlns:th="http://www.thymeleaf.org">
<head>
    <meta charset="utf-8">
    <title>后台管理系统</title>
    <meta name="renderer" content="webkit">
    <meta http-equiv="X-UA-Compatible" content="IE=edge,chrome=1">
    <meta name="viewport"
          content="width=device-width, initial-scale=1.0, minimum-scale=1.0, maximum-scale=1.0, user-scalable=0">
    <link rel="stylesheet" media="all" th:href="@{/admin/layui/css/layui.css}">
    <link rel="stylesheet" media="all" th:href="@{/admin/style/admin.css}">
</head>
<body class="layui-layout-body">

<div id="LAY_app">
    <div class="layui-layout layui-layout-admin">

        <!-- 头部区域 -->
        <div th:replace="main/header::header"></div>

        <!-- 侧边菜单 -->
        <div th:replace="main/left::left"></div>

        <!-- 页面标签 -->
        <div th:replace="main/tabs::tabs"></div>

        <!-- 主体内容 -->
        <div th:replace="main/body::body"></div>

        <!-- 辅助元素，一般用于移动设备下遮罩 -->
        <div class="layadmin-body-shade" layadmin-event="shade"></div>
    </div>
</div>
<script type="text/html" id="menuTpl">
    <li data-name="home" class="layui-nav-item layui-nav-itemed">
        <a href="javascript:;" lay-href="/home" lay-tips="主页" lay-direction="2">
            <i class="layui-icon layui-icon-home"></i>
            <cite>主页</cite>
        </a>
    </li>
    {{#  layui.each(d, function(index, item){}}
    <li data-name="component" class="layui-nav-item">
        <a href="javascript:;" {{ item.url ? 'lay-href="' + item.url + '"' : '' }} lay-tips="{{item.name}}"
        lay-direction="2">
        <i class="layui-icon {{item.icon}}"></i>
        <cite>{{item.name}}</cite>
        </a>
        {{# if (item.children){ }}
        <dl class="layui-nav-child">
            {{# layui.each(item.children, function(idx, children){ }}
            <dd data-name="{{children.name}}">
                <i class="layui-icon {{children.icon}}"></i>
                <a lay-href="{{children.url}}">{{children.name}}</a>
            </dd>
            {{# }) }}
        </dl>
        {{# } }}
    </li>
    {{#  }); }}
</script>
<script th:src="@{/admin/layui/layui.js}"></script>
<script>
    layui.config({
        base: '/admin/' //静态资源所在路径
    }).extend({
        index: 'lib/index' //主入口模块
    }).use([
        'index', 'admin', 'layer', 'element', 'laytpl'
    ], function () {
        var $ = layui.$, layer = layui.layer, admin = layui.admin, element = layui.element, laytpl = layui.laytpl;

        //执行 Ajax 后重载
        admin.req({
            url: '/sys/menu/menuTree'
            , done: function (res) {
                var menuTpl = document.getElementById('menuTpl').innerHTML;
                var menuView = document.getElementById('menuView');
                laytpl(menuTpl).render(res.data, function (html) {
                    menuView.innerHTML = html;
                });
                element.render('nav');
            }
        });

        $(".logout").click(function () {
            layer.confirm('确定退出？', {
                icon: 3,
                title: '退出提示',
                btn: ['确定', '取消'] //按钮
            }, function () {
                admin.req({
                    url: 'logout'
                    , done: function () {
                        window.location.href = "main";
                    }
                });
            });
        });
    });
</script>
</body>
</html>